<template>
	<view class="">
		<navBar title="首检"></navBar>
		<handling :text="text" @statusdetails="statusdetails"></handling>
		<tableList :pageTurning="pageTurning" :dataList="dataList" :selectionBox="false" @particulars="particularsUrl">
		</tableList>
		<view class="w-100% h-60rpx"></view>
	</view>
</template>

<script lang="ts" setup>
	import navBar from '@/components/navbar.vue'
	import tableList from '@/components/tableList.vue'
	import handling from '@/components/handling.vue'
	import { selectPadTask } from '@/common/api/operationApi'
	import { onShow, onReachBottom } from "@dcloudio/uni-app"
	import { ref } from 'vue'
	const dataList = ref<string[]>([])
	const text = ref<any>({
		text1: '待办',
		text2: '已办'
	})
	const status = ref<number>(1)
	const statusdetails = (val : any) => {
		status.value = val
		page.value = 1
		tabList()
	}
	onShow(() => {
		page.value = 1
		tabList()
	})
	const pageTurning = ref<boolean>(false)
	onReachBottom(() => {
		if (numberpages.value >= page.value) {
			page.value++
			selectPadTask({
				status: status.value,
				taskType: 10,
				page: page.value,
				size: size.value,
				processCode: processCode.value
			}).then((data) => {
				dataList.value.push(...data.items)
				data.items.length === 20 ? pageTurning.value = true : pageTurning.value = false
			})
		}
	})
	const page = ref<number>(1)
	const size = ref<number>(20)
	const numberpages = ref<number>()
	const processCode = ref<number>(0)
	async function tabList() : Promise<void> {
		const data = await selectPadTask({
			status: status.value,
			taskType: 10,
			page: page.value,
			size: size.value,
			processCode: processCode.value
		})
		dataList.value = data.items
		numberpages.value = Math.ceil(data.count / size.value)
		data.items.length === 20 ? pageTurning.value = true : pageTurning.value = false
	}
	function particularsUrl(prodWork : string[], processDesc : string, id : string[]) {
		var url = ''
		if (status.value === 1) {
			url = `/pages/FirstInspection/needToBeDealtWith?processDesc=${processDesc}&prodWorkList=${prodWork}&id=${id}`
		} else {
			url = `/pages/FirstInspection/alreadyHandled?processDesc=${processDesc}&prodWorkList=${prodWork}&id=${id}`
		}
		uni.navigateTo({
			url: url
		});
	}
</script>

<style scoped>

</style>